<?php

namespace app\api\controller;

use app\common\controller\Api;
use fast\Random;
use think\Db;
use app\api\controller\Common;
use fast\Http;
use app\common\controller\MyHelp;

/**
 * 快递
 */
class Kuaidi
{

    public static function sdcccfgggg($body, $api)
    {
        $key = 'wngb7sq17cghpgsv';
        $data = [
            'privateKey' => $key,
            'timestamp' => time() . '123',
            'username' => 'laojin',
        ];

        $sign = strtoupper(MD5(json_encode($data)));
        //  $data['businessParams'] = $body;
        if ($body) {
            $data['businessParams'] = $body;
        }
        $data['apiMethod'] = $api;
        $data['sign'] = $sign;

        $headers = ['Content-type: application/json'];
        $options = [
            CURLOPT_HTTPHEADER => $headers
        ];
        return   Http::post('https://www.yida178.cn/prod-api/thirdApi/execute', json_encode($data), $options);
    }
    public static function qprice($body)
    {

        if (substr($body['receiveMobile'], 0, 1) != '1') { //按电话处理
            $body['receiveTel'] = $body['receiveMobile'];
            unset($body['receiveMobile']);
        }
        if (substr($body['senderMobile'], 0, 1) != '1') { //按电话处理
            $body['senderTel'] = $body['senderMobile'];
            unset($body['senderTel']);
        }
        return  self::sdcccfgggg($body, 'SMART_PRE_ORDER');
    }
    public static function suborder($body)
    {
        if (substr($body['receiveMobile'], 0, 1) != '1') { //按电话处理
            $body['receiveTel'] = $body['receiveMobile'];
            unset($body['receiveMobile']);
        }
        if (substr($body['senderMobile'], 0, 1) != '1') { //按电话处理
            $body['senderTel'] = $body['senderMobile'];
            unset($body['senderTel']);
        }
        return  self::sdcccfgggg($body, 'SUBMIT_ORDER_V2');
    }
    public  static function cancelOrder($deliveryType = 'STO-INT', $deliveryId = '775630060980382')
    {
        $body = [
            'deliveryType' => $deliveryType,
            'deliveryId' =>  $deliveryId
        ];
        // {
        //     "code": 500,
        //     "msg": "不支持的deliveryType:STO",
        //     "data": false,
        //     "tid": "1580083466185428992"
        //     }
        //{"code":200,"msg":"运单取消成功","data":true,"tid":"1583279882680586240"}
        return  self::sdcccfgggg($body, 'CANCEL_ORDER');
    }
    public static  function Qdelivery($deliveryType = 'YUND', $deliveryId = '5302002031930')
    {
        $body = [
            'deliveryType' => $deliveryType,
            'deliveryId' =>  $deliveryId
        ];
        // {
        //     "code": 500,
        //     "msg": "不支持的deliveryType:STO",
        //     "data": false,
        //     "tid": "1580083466185428992"
        //     }
        //{"code":200,"msg":"查询轨迹信息成功","data":null,"tid":"1583296769602805760"}
        return  self::sdcccfgggg($body, 'DELIVERY_TRACE');
    }
    public static function dewu()
    {
        return  self::sdcccfgggg('', 'QUERY_POIZON_ADDRESS');
    }

    public function smartparse1($address = '邮寄地址：北京市大兴区亦庄经济开发区科创十一街18号院京东大厦B座13层
    收件人：廉萌
    联系电话：400-630-3180（客服电话工作时间为：周一至周五9:00-12:00,13:00-18:00）')
    {
        $headers = ['Authorization: APPCODE d706e6ced7fe4cd4820a7950d92b5ff9'];
        $options = [
            CURLOPT_HTTPHEADER => $headers
        ];

        //qrservice.market.alicloudapi.com/createQrCode
        $r = http::get('http:///jiexi8.market.alicloudapi.com/address/analysis?text=' . urlencode($address) . '', [], $options);
        return $r;
        $r_arr = json_decode($r, true);
        //{ "showapi_res_error": "", "showapi_res_id": "62e5f2570de3760061887060", "showapi_res_code": 0, "showapi_fee_num": 1, "showapi_res_body": {"msg":"操作成功!","imgUrl":"http://static1.showapi.com/app2/img/qrCode/20220731/1659236951207.png","flag":"true","ret_code":0} }
        if (isset($r_arr['showapi_res_body']['imgUrl'])) {
            // Cache::set('code_' . $type . $admin_id, $r_arr['showapi_res_body']['imgUrl'],);
            return $r_arr['showapi_res_body']['imgUrl'];
        } else {
            return  '';
        }
    }

    /**
     * 地址智能解析
     * @param string 包含丰富信息的字符串
     * @return array 姓名，手机号，邮编，详细地址
     */
    public static  function smartparse($address = '身份证号：51250119910927226x 收货地址张三收货地址：四川省成都市武侯区美领馆路11号附2号 617000  136-3333-6666 ')
    {
        //$obj = $this->smart_parse('身份证号：51250119910927226x 收货地址张三收货地址：成都市武侯区美领馆路11号附2号 617000  136-3333-6666 ');
        //解析结果
        $parse = [];
        $parse['name']     = '';
        $parse['mobile']   = '';
        $parse['postcode'] = '';
        $parse['idno']     = '';
        $parse['detail']   = '';
        $address = str_replace('-', '', $address);
        //收货人: 张玉手机号码: 15961287537所在地区: 江苏省淮安市淮阴区刘老庄镇详细地址: 振兴路刘老庄镇双庄社区
        //1. 过滤掉收货地址中的常用说明字符，排除干扰词
        $search = ['收货地址', '邮寄地址', '地址', '寄件人', '快递收货人', '快递寄件人', '快递', '收货人', '收件人', '收货', '邮编',  '联系电话', '电话', '身份证号码', '身份证号', '身份证', '：', ':', '；', ';', '，', ',', '。', '手机号码', '所在地区', '详细'];
        $replace = [' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '];
        //  邮寄地址：北京市大兴区亦庄经济开发区科创十一街18号院京东大厦B座13层收件人：廉萌 联系电话：400-630-3180（客服电话工作时间为：周一至周五9:00-12:00,13:00-18:00）
        $address = str_replace($search, $replace, $address);

        //2. 连续2个或多个空格替换成一个空格
        $address = preg_replace('/ {2,}/', ' ', $address);

        //3. 去除手机号码中的短横线 如136-3333-6666 主要针对苹果手机
        $address = preg_replace('/(\d{3})-(\d{4})-(\d{4})/', '$1$2$3', $address);
        // echo $address;
        //  exit;
        //4. 提取中国境内身份证号码
        preg_match('/\d{18}|\d{17}X/i', $address, $match);
        if ($match && $match[0]) {
            $parse['idno'] = strtoupper($match[0]);
            $address = str_replace($match[0], '', $address);
        }

        //5. 提取11位手机号码或者7位以上座机号
        preg_match('/\d{7,11}|\d{3,4}-\d{6,8}/', $address, $match);
        if ($match && $match[0]) {
            $parse['mobile'] = $match[0];
            $address = str_replace($match[0], '', $address);
        }

        //6. 提取6位邮编 邮编也可用后面解析出的省市区地址从数据库匹配出
        preg_match('/\d{6}/', $address, $match);
        if ($match && $match[0]) {
            $parse['postcode'] = $match[0];
            $address = str_replace($match[0], '', $address);
        }

        //再次把2个及其以上的空格合并成一个，并首位TRIM
        $address = trim(preg_replace('/ {2,}/', ' ', $address));

        //按照空格切分 长度长的为地址 短的为姓名 因为不是基于自然语言分析，所以采取统计学上高概率的方案
        $split_arr = explode(' ', $address);
        // echo json_encode($split_arr);
        // exit;
        if (count($split_arr) > 1) {
            $parse['name'] = $split_arr[0];
            $parse['detail'] = $split_arr[0];


            foreach ($split_arr as $value) {
                if (strlen($value) < strlen($parse['name']) && preg_match("/^[\x7f-\xff]+$/", $value)) {
                    $parse['name'] = $value;
                }
                if (strlen($value) > strlen($parse['detail'])) {
                    $parse['detail'] = $value;
                }
            }
            $address = $parse['detail'];
            // $address = trim(str_replace($parse['name'], '', $address));
        }

        $parse['detail'] = $address;
        $detail = self::get_address($address);
        $parse['province'] = $detail['province'];
        $parse['city'] = $detail['city'];
        $parse['district'] = $detail['district'];
        $parse['address'] = $detail['address'];

        // echo json_encode($parse);
        // exit;

        //parse['detail']详细地址可以传入另一个文件的函数，用来解析出：省，市，区，街道地址
        return $parse;
    }
    public static  function get_address($address)
    {
        preg_match('/(.*?(省|自治区|北京市|天津市|上海市|重庆市|澳门特别行政区|香港特别行政区))/', $address, $matches);
        if (count($matches) > 1) {
            $province = $matches[count($matches) - 2];

            $address = preg_replace('/(.*?(省|自治区|北京市|天津市|上海市|重庆市|澳门特别行政区|香港特别行政区))/', '', $address, 1);
        }
        preg_match('/(.*?(市|自治州|地区|区划|县))/', $address, $matches);
        if (count($matches) > 1) {
            $city = $matches[count($matches) - 2];
            $address = str_replace($city, '', $address);
        }
        preg_match('/(.*?(区|县|镇|乡|街道))/', $address, $matches);
        if (count($matches) > 1) {
            $area = $matches[count($matches) - 2];
            $address = str_replace($area, '', $address);
        }
        if (isset($province)) {
            if ($province == "北京" || $province == "北京市") {
                $province = "北京市";
                $city = "北京市";
            }
            if ($province == "天津" || $province == "天津市") {
                $province = "天津市";
                $city = "天津市";
            }
            if ($province == "重庆" || $province == "重庆市") {
                $province = "重庆市";
                $city = "重庆市";
            }
            if ($province == "上海" || $province == "上海市") {
                $province = "上海市";
                $city = "上海市";
            }
        }
        return [
            'province' => isset($province) ? $province : '',
            'city' => isset($city) ? $city : '',
            'district' => isset($area) ? $area : '',
            "address" => $address
        ];
    }
    /**
     * 智能地址解析
     */
    public static  function get_addressNew($address = '收货姓名张三收货地址：四川省成都市武侯区美领馆路11号附2号 617000  13633336666')
    {
        $address = str_replace('-', '', $address);
        //收货人: 张玉手机号码: 15961287537所在地区: 江苏省淮安市淮阴区刘老庄镇详细地址: 振兴路刘老庄镇双庄社区
        //1. 过滤掉收货地址中的常用说明字符，排除干扰词
        $search = ['收货地址', '邮寄地址', '地址', '寄件人', '快递收货人', '快递寄件人', '快递', '收货人', '收件人', '收货', '邮编',  '联系电话', '电话', '身份证号码', '身份证号', '身份证', '：', ':', '；', ';', '，', ',', '。', '手机号码', '所在地区', '详细'];
        $replace = [' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '];
        //  邮寄地址：北京市大兴区亦庄经济开发区科创十一街18号院京东大厦B座13层收件人：廉萌 联系电话：400-630-3180（客服电话工作时间为：周一至周五9:00-12:00,13:00-18:00）
        $address = str_replace($search, $replace, $address);

        //2. 连续2个或多个空格替换成一个空格
        $address = preg_replace('/ {2,}/', ' ', $address);

        //3. 去除手机号码中的短横线 如136-3333-6666 主要针对苹果手机
        $address = preg_replace('/(\d{3})-(\d{4})-(\d{4})/', '$1$2$3', $address);
        $url = 'https://fun-api.huanxio.com/wuliu/smartAddress';
        $data = [
            'text' => $address,
            'auth_appid' => 'wxc845181b3978cbbc'
        ];
        $headers = ['Content-type: application/json'];
        $options = [
            CURLOPT_HTTPHEADER => $headers
        ];
        $rst =   Http::post($url, json_encode($data), $options);
        $rst_arr = json_decode($rst, true);
        if ($rst_arr['code'] == '0') {
            $parse['province'] = $rst_arr['result']['province'];
            $parse['city'] = $rst_arr['result']['city'];
            $parse['county'] = $rst_arr['result']['county'];
            $parse['address'] = $rst_arr['result']['detail'];
            $parse['phonenum'] = $rst_arr['result']['phonenum'];
            $parse['name'] = $rst_arr['result']['person'];

            return json_encode(['code' => '1', 'msg' => '请求成功', 'data' => $parse]);
        } else {
            return json_encode(['code' => '0', 'msg' => '请求异常']);
        }
    }
    /**
     * 云洋订单回调
     */
    public  function yycallback()
    {
        $postData = file_get_contents('php://input');
        MyHelp::dingding("快递推送订单：" . $postData, '3acdcd1692e6ca3fee6bf21ba73c6a837e1ff69b95d63a4be3c7bd3df25886b6');
        $postData_arr = json_decode($postData, true);
        $shopbill = $postData_arr['shopbill'];
        $typeCode = $postData_arr['typeCode']; //	状态码（1.待揽收 2.运输中 3.已签收 4.拒收退回 99.已取消）
        $calWeight = $postData_arr['calWeight']; //扣费重量
        $totalFreight = $postData_arr['totalFreight']; //总扣款
        $freightInsured = $postData_arr['freightInsured']; //保价
        $feeOver = $postData_arr['feeOver']; //订单扣费状态（1:已扣费 0:冻结）
        $freightHaocai = $postData_arr['freightHaocai']; //其他耗材费用

        $comments = $postData_arr['comments'];
        $courierPhone = $postData_arr['courierPhone'];
        $courierName = $postData_arr['courierName'];
        $pickupCode = $postData_arr['pickupCode'];
        $order =   db::table('fa_kd_order')->where('api_order', $shopbill)->find();
        if (!$order) {
            return '{"code":1,"message":"推送成功"}';
        }
        //状态:1=未付款,2=已下单,3=成功完成,4=失败退款,5=待取件,6=运输中,7=已签收,8=拒收退回
        if ($order['statuss'] == '3' || $order['statuss'] == '4') {
            return '{"code":1,"message":"推送成功"}';
        }
        if ($typeCode == '1') {
            $data['courierName'] = $courierName;
            $data['courierPhone'] = $courierPhone;
            $data['pickUpCode'] = $pickupCode;
            // $data['calWeight'] = $calWeight;

            $data['statuss'] = '5';
            db::table('fa_kd_order')->where('api_order', $shopbill)->update($data);
        } elseif ($typeCode == '2') {
            // $data['calWeight'] = $calWeight;
            $data['courierName'] = $courierName;
            $data['courierPhone'] = $courierPhone;
            $data['pickUpCode'] = $pickupCode;
            $data['statuss'] = '6';
            db::table('fa_kd_order')->where('api_order', $shopbill)->update($data);
        } elseif ($typeCode == '3') {
            $data['statuss'] = '7';
            db::table('fa_kd_order')->where('api_order', $shopbill)->update($data);
        } elseif ($typeCode == '4') {
            $data['statuss'] = '8';
            db::table('fa_kd_order')->where('api_order', $shopbill)->update($data);
        } elseif ($typeCode == '99') {
            $data['statuss'] = '4'; //退了
            db::table('fa_kd_order')->where('api_order', $shopbill)->update($data);
        }
        // return $feeOver;
        if ($feeOver == 1) { //已确定扣费
            //更新一下扣费重量
            $data_price['calWeight'] = $calWeight;
            $data_price['c_freight'] = round($totalFreight - $order['cbprice']);
            if ($order['cbprice'] != $totalFreight) { //成本价不等于总费用

                $data_price['cbprice'] = $totalFreight; //新成本价
                if ($order['payType'] == 2) {
                    $sxf = round($totalFreight * 0.002, 2);
                    $freightNi = round($totalFreight * 0.05, 2); //总利润

                    $zz_lr = round($freightNi * 0.4, 2);
                    $lirun = round($freightNi - $sxf - $zz_lr, 2);
                } else {
                    $sxf = round($totalFreight * 0.006, 2);
                    $freightNi = round($totalFreight * 0.05, 2); //总利润

                    $zz_lr = round($freightNi * 0.3, 2);
                    $lirun = round($freightNi - $sxf - $zz_lr, 2);
                }
                // return $lirun;
                $data_price['sxf'] = $sxf;
                $data_price['zz_lr'] = $zz_lr; //新成本价
                $data_price['lirun'] = $lirun; //新成本价
                $data_price['price'] = round($totalFreight * 1.05, 2); //新成本价
                db::table('fa_kd_order')->where('api_order', $shopbill)->update($data_price);
                $wo = db::table('fa_kd_order_weight')->where('order_id', $order['id'])->find();
                $new = [
                    'order_id' => $order['id'],
                    'user_id' => $order['user_id'],
                    'weight' => $order['weight'],
                    'price' => $order['price'],
                    'lirun' => $order['lirun'],
                    'cbprice' => $order['cbprice'],
                    'sxf' => $order['sxf'],

                    'calWeight' => $calWeight,
                    'zz_lr_new' => $zz_lr,
                    'lirun_new' => $lirun,
                    'cbprice_new' => $totalFreight,
                    'sxf_new' => $sxf,
                    'createtime' => time()
                ];
                if ($wo) {
                    db::table('fa_kd_order_weight')->where('order_id', $order['id'])->update($new);
                } else {
                    db::table('fa_kd_order_weight')->insert($new);
                }


                //更新费用
            }
            //这里确定扣费逻辑
            //变了就要么退要么补 没变就不动  支付分部分确定扣款

        }
        if ($freightInsured > 0) {
            db::table('fa_kd_order')->where('api_order', $shopbill)->update(['freightInsured' => $freightInsured]);
        }
        return '{"code":1,"message":"推送成功"}';
    }
    /**
     * 云洋工单回调
     */
    public  function yycallbackgd()
    {
        $postData = file_get_contents('php://input');
        MyHelp::dingding("快递工单订单：" . $postData, '3acdcd1692e6ca3fee6bf21ba73c6a837e1ff69b95d63a4be3c7bd3df25886b6');
        return '{"code":1,"message":"推送成功"}';
    }
    /**
     * 云洋支付分回调
     */
    public  function yycallbackZff()
    {
        $postData = file_get_contents('php://input');
        MyHelp::dingding("快递支付分订单：" . $postData, '3acdcd1692e6ca3fee6bf21ba73c6a837e1ff69b95d63a4be3c7bd3df25886b6');
        return '{"code":1,"message":"推送成功"}';
    }
    /**
     * 云洋查询渠道
     */
    public static  function yy_checkChannel($request)
    {
        $url = 'https://api.yunyangwl.com/api/wuliu/openService';
        $time = time() . '111';
        $appid = '926B42FC96384A81B4A3C7954CA8192F';
        $appkey = '4df652f0-a734-4077-9498-e81b1a711512';
        $requestId = Random::uuid();
        $request['channelTag'] = '智能';
        $data = [
            'serviceCode' => 'CHECK_CHANNEL_INTELLECT',
            'timeStamp' => $time,
            'requestId' => $requestId,
            'appid' => $appid,
            'content' => $request
        ];
        $sign = md5($appid . $requestId . $time . $appkey);
        $data['sign'] = $sign;
        $headers = ['Content-type: application/json'];
        $options = [
            CURLOPT_HTTPHEADER => $headers
        ];
        return   Http::post($url, json_encode($data), $options);
    }
    /**
     * 云洋查询价格
     */
    public static  function yy_checkPrice($request)
    {
        $url = 'https://api.yunyangwl.com/api/wuliu/openService';
        $time = time() . '111';
        $appid = '926B42FC96384A81B4A3C7954CA8192F';
        $appkey = '4df652f0-a734-4077-9498-e81b1a711512';
        $requestId = Random::uuid();
        // $request['channelTag'] = '智能';
        $data = [
            'serviceCode' => 'QUERY_ORIGINAL_PRICE',
            'timeStamp' => $time,
            'requestId' => $requestId,
            'appid' => $appid,
            'content' => $request
        ];
        $sign = md5($appid . $requestId . $time . $appkey);
        $data['sign'] = $sign;
        $headers = ['Content-type: application/json'];
        $options = [
            CURLOPT_HTTPHEADER => $headers
        ];
        return   Http::post($url, json_encode($data), $options);
    }
    /**
     * 云洋支付分下单
     */
    public static  function yy_zffOrder()
    {
        $url = 'https://api.yunyangwl.com/api/open/payscore/payScoreService';
        $time = time() . '111';
        $appid = '926B42FC96384A81B4A3C7954CA8192F';
        $appkey = '4df652f0-a734-4077-9498-e81b1a711512';
        $requestId = Random::uuid();
        $request = [
            'sub_mchid' => '1663340087',
            'sub_appid' => 'wx2f396da944f64fe8',
            'out_order_no' => '5555555555',
            'service_introduction' => '先寄后付',
            'risk_fund' => [
                'name' => 'ADVANCE',
                'amount' => 56,
                'description' => '无需预付快捷寄件，快递寄出后自动支付实际产生的快递费。',
            ],
            'time_range' => [
                'start_time' => 'OnAccept',
                'start_time_remark' => '说明'
            ],
            'sub_openid' => ''
        ];
        //$request['channelTag'] = '智能';
        $data = [
            'serviceCode' => 'CREATE_PAY_SCORE',
            'timeStamp' => $time,
            'requestId' => $requestId,
            'appid' => $appid,
            'content' => $request
        ];
        $sign = md5($appid . $requestId . $time . $appkey);
        $data['sign'] = $sign;
        $headers = ['Content-type: application/json'];
        $options = [
            CURLOPT_HTTPHEADER => $headers
        ];
        return   Http::post($url, json_encode($data), $options);
    }

    /**
     * 云洋下单
     */
    public static  function yy_subOrder($request = [])
    {
        $url = 'https://api.yunyangwl.com/api/wuliu/openService';
        $time = time() . '111';
        $appid = '926B42FC96384A81B4A3C7954CA8192F';
        $appkey = '4df652f0-a734-4077-9498-e81b1a711512';
        $requestId = Random::uuid();

        $r = '{
        	"sender": "杨ff",
        	"senderMobile": "18838000101",
        	"senderProvince": "四川省",
        	"senderCity": "成都市",
        	"senderCounty": "双流区",
        	"senderLocation": "天目中心13栋",
        	"receiver": "杨xx",
        	"receiverMobile": "18801010202",
        	"receiveProvince": "广东省",
        	"receiveCity": "东莞市",
        	"receiveCounty": "塘厦镇",
        	"receiveLocation": "高裕北路118号广东建隆实业2栋8楼",
        	"weight": "1",
        	"packageCount": "1",
        	"itemName": "键盘",
        	"billRemark": "无备注"
        }';
        $request = json_decode($r, true);
        $request['channelTag'] = '智能';
        $data = [
            'serviceCode' => 'ADD_BILL_INTELLECT',
            'timeStamp' => $time,
            'requestId' => $requestId,
            'appid' => $appid,
            'content' => $request
        ];
        $sign = md5($appid . $requestId . $time . $appkey);
        $data['sign'] = $sign;
        $headers = ['Content-type: application/json'];
        $options = [
            CURLOPT_HTTPHEADER => $headers
        ];
        //   return json($data);
        return   Http::post($url, json_encode($data), $options);
        //{"id":"fcec10b2-0533-493b-a9e5-9dd932803b9e","code":"414","message":"您的警戒金额为：100.00元，可用金额不能低于警戒金额,请充值","result":"您的警戒金额为：100.00元，可用金额不能低于警戒金额,请充值","error":null}

    }
    /**
     * 云洋取消订单
     * 状态码：0失败，1成功
     */
    public  function yy_delOrder($shopbill = '11')
    {
        $url = 'https://api.yunyangwl.com/api/wuliu/openService';
        $time = time() . '111';
        $appid = '926B42FC96384A81B4A3C7954CA8192F';
        $appkey = '4df652f0-a734-4077-9498-e81b1a711512';
        $requestId = Random::uuid();
        $data = [
            'serviceCode' => 'CANCEL',
            'timeStamp' => $time,
            'requestId' => $requestId,
            'appid' => $appid,
            'content' => [
                'shopbill' => $shopbill,
            ]
        ];
        $sign = md5($appid . $requestId . $time . $appkey);
        $data['sign'] = $sign;
        $headers = ['Content-type: application/json'];
        $options = [
            CURLOPT_HTTPHEADER => $headers
        ];
        return   Http::post($url, json_encode($data), $options);
        //{"id":"2efe387e-6d3f-4b5f-84ba-60dc087f8d8e","code":"0","message":"待执行的订单信息有误","result":null,"error":null}
    }
    /**
     * 云洋查询物流详情
     * 
     */
    public static function yy_trance($shopbill = '268118897607553578')
    {
        $url = 'https://api.yunyangwl.com/api/wuliu/openService';
        $time = time() . '111';
        $appid = '926B42FC96384A81B4A3C7954CA8192F';
        $appkey = '4df652f0-a734-4077-9498-e81b1a711512';
        $requestId = Random::uuid();
        $data = [
            'serviceCode' => 'QUERY_TRANCE',
            'timeStamp' => $time,
            'requestId' => $requestId,
            'appid' => $appid,
            'content' => [
                'shopbill' => $shopbill,
                'traceFormat' => 'obj'
            ]
        ];
        $sign = md5($appid . $requestId . $time . $appkey);
        $data['sign'] = $sign;
        $headers = ['Content-type: application/json'];
        $options = [
            CURLOPT_HTTPHEADER => $headers
        ];
        return   Http::post($url, json_encode($data), $options);
        //{"id":"35beac86-96dd-4c0a-ac5f-74800af70a9a","code":"1","message":"成功","result":[{"comments":"快递员姓名:窦勇坤，电话:17780033849，取件码："}],"error":null}
        //{"id":"12c8947c-24b5-4761-a27c-41cc5311b5d7","code":"0","message":"查询信息有误","result":null,"error":null}
    }
    /**
     * 云洋查询物流详情
     * 
     */
    public static function yy_price($shopbill = '268118897607553578')
    {
        $url = 'https://api.yunyangwl.com/api/wuliu/openService';
        $time = time() . '111';
        $appid = '926B42FC96384A81B4A3C7954CA8192F';
        $appkey = '4df652f0-a734-4077-9498-e81b1a711512';
        $requestId = Random::uuid();
        $data = [
            'serviceCode' => 'QUERY_TRANCE',
            'timeStamp' => $time,
            'requestId' => $requestId,
            'appid' => $appid,
            'content' => [
                'shopbill' => $shopbill,
                'traceFormat' => 'obj'
            ]
        ];
        $sign = md5($appid . $requestId . $time . $appkey);
        $data['sign'] = $sign;
        $headers = ['Content-type: application/json'];
        $options = [
            CURLOPT_HTTPHEADER => $headers
        ];
        return   Http::post($url, json_encode($data), $options);
        //{"id":"35beac86-96dd-4c0a-ac5f-74800af70a9a","code":"1","message":"成功","result":[{"comments":"快递员姓名:窦勇坤，电话:17780033849，取件码："}],"error":null}
        //{"id":"12c8947c-24b5-4761-a27c-41cc5311b5d7","code":"0","message":"查询信息有误","result":null,"error":null}
    }
    /**
     * 云洋取消订单
     * 
     */
    public static function yy_CANCEL($shopbill = '268118897607553578')
    {
        $url = 'https://api.yunyangwl.com/api/wuliu/openService';
        $time = time() . '111';
        $appid = '926B42FC96384A81B4A3C7954CA8192F';
        $appkey = '4df652f0-a734-4077-9498-e81b1a711512';
        $requestId = Random::uuid();
        $data = [
            'serviceCode' => 'CANCEL',
            'timeStamp' => $time,
            'requestId' => $requestId,
            'appid' => $appid,
            'content' => [
                'shopbill' => $shopbill,
                'traceFormat' => 'obj'
            ]
        ];
        $sign = md5($appid . $requestId . $time . $appkey);
        $data['sign'] = $sign;
        $headers = ['Content-type: application/json'];
        $options = [
            CURLOPT_HTTPHEADER => $headers
        ];
        return   Http::post($url, json_encode($data), $options);
        //{"id":"08aa8c1a-2c1c-4d3a-88e3-79b9b83c03cf","code":"0","message":"该订单已取消","result":"该订单已取消","error":null}
    }
    /**
     * 云洋查询余额
     */
    public  function yy_yue()
    {
        $url = 'https://api.yunyangwl.com/api/wuliu/openService';
        $time = time() . '111';
        $appid = '926B42FC96384A81B4A3C7954CA8192F';
        $appkey = '4df652f0-a734-4077-9498-e81b1a711512';
        $requestId = Random::uuid();
        $data = [
            'serviceCode' => 'QUERY_BALANCE',
            'timeStamp' => $time,
            'requestId' => $requestId,
            'appid' => $appid,
            'content' => [
                '' => ''
            ]
        ];
        $sign = md5($appid . $requestId . $time . $appkey);
        $data['sign'] = $sign;
        $headers = ['Content-type: application/json'];
        $options = [
            CURLOPT_HTTPHEADER => $headers
        ];
        // return json_encode($data);
        return   Http::post($url, json_encode($data), $options);
        //{"id":"144384f7-24ec-40e4-bddc-5d38e5bf6094","code":"200","message":"OK","result":{"yue":0.00,"keyong":0.00,"dongjie":0.00},"error":null}
    }

    /**
     * 云洋同城闪送
     */
    public static function yy_tongcheng_ss($request)
    {
        $url = 'https://api.yunyangwl.com/api/wuliu/newCityService';
        $time = time() . '111';
        $appid = '926B42FC96384A81B4A3C7954CA8192F';
        $appkey = '4df652f0-a734-4077-9498-e81b1a711512';
        $requestId = Random::uuid();
        $data = [
            'serviceCode' => 'QUERY_DELIVER_FEE',
            'timeStamp' => $time,
            'requestId' => $requestId,
            'appid' => $appid,
            'content' => $request
        ];
        $sign = md5($appid . $requestId . $time . $appkey);
        $data['sign'] = $sign;
        $headers = ['Content-type: application/json'];
        $options = [
            CURLOPT_HTTPHEADER => $headers
        ];
        // return json_encode($data);
        return   Http::post($url, json_encode($data), $options);
        //{"id":"144384f7-24ec-40e4-bddc-5d38e5bf6094","code":"200","message":"OK","result":{"yue":0.00,"keyong":0.00,"dongjie":0.00},"error":null}
    }
    //1707051533914476544
}
